import { Sequelize } from "sequelize-typescript";
import DataModel from '../model/data'
import DateModel from '../model/date'
import StatusModel from '../model/status'
import UserModel from '../model/user'
import MsgModel from '../model/msg'
import test from "../config/db"
import {dbLogger} from "./log"
import {resolve} from 'path'
const sequelize = new Sequelize({
    ...test,
    logging: false,
    pool: {
        min: 0,
        max: 5
    }

})
// 添加数据库模型
sequelize.addModels([resolve(__dirname,'../model')]);

// 判断数据库是否初始化
sequelize.authenticate().then(() => {
    console.log('Connection has been established successfully.')
})
.catch(err => {
    console.error('Unable to connect to the database:', err)
});

// 同步本地数据库
sequelize.sync().then(res => {
    console.log("同步数据库成功")
})

export {sequelize,DataModel,DateModel,StatusModel,UserModel,MsgModel}
